home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / libs / pdcurs21 / portable / overwrit.c < prev    next >
C/C++ Source or Header  |  1993-06-18  |  3KB  |  113 lines

  1. #define    CURSES_LIBRARY    1
  2. #include <curses.h>
  3. #undef    overwrite
  4.  
  5. #ifdef PDCDEBUG
  6. char *rcsid_overwrit = "$Header: C:\CURSES\portable\RCS\overwrit.c 2.1 1993/06/18 20:19:18 MH Rel MH $";
  7. #endif
  8.  
  9.  
  10.  
  11.  
  12. /*man-start*********************************************************************
  13.  
  14.   overwrite()    - Overwrite windows
  15.  
  16.   X/Open Description:    overlay() and overwrite()
  17.      These functions overlay src_w on top of dst_w; that is,
  18.      all text in src_w is copied into dst_w. The windows
  19.      src_w and dst_w are not required to be the same size. The
  20.      copy starts at (0, 0) on each window. The difference between
  21.      the two functions is that overlay() is non-destructive
  22.      (blanks are not copied) while overwrite() is destructive
  23.      (blanks are copied).
  24.  
  25.   PDCurses Description:
  26.      The above description is misleading in the actual behaviour
  27.      exhibited by both SysV and BSD curses. The above implies that
  28.      the character in 0,0 of the source window is copied to 0,0 of
  29.      the destination window. What actually happens is that those
  30.      characters in the source window that intersect with characters
  31.      in the destination window RELATIVE TO ABSOLUTE 0,0 ON THE SCREEN, 
  32.      are copied to the destination window so that the characters appear 
  33.      in the same physical position on the screen.
  34.  
  35.      Thanks to Andreas Otte (venn@uni-paderborn.de) for the correction
  36.      and code changes.
  37.  
  38.   X/Open Return Value:
  39.      The overwrite() function returns OK on success and ERR on error.
  40.  
  41.   PDCurses Errors:
  42.      It is an error to pass a NULL window pointer.
  43.  
  44.   Portability:
  45.      PDCurses    int    overwrite( WINDOW* src_w, WINDOW* dst_w );
  46.      X/Open Dec '88    int    overwrite( WINDOW* src_w, WINDOW* dst_w );
  47.      BSD Curses    int    overwrite( WINDOW* src_w, WINDOW* dst_w );
  48.      SYS V Curses    int    overwrite( WINDOW* src_w, WINDOW* dst_w );
  49.  
  50. **man-end**********************************************************************/
  51.  
  52. int    overwrite(WINDOW *src_w, WINDOW *dst_w)
  53. {
  54.     int    last_line;
  55.     int    last_col;
  56.     int    first_line;
  57.     int    first_col;
  58.     int    src_start_x;
  59.     int    src_start_y;
  60.     int    dst_start_x;
  61.     int    dst_start_y;
  62.     int    xdiff;
  63.     int    ydiff;
  64.     int    rc;
  65.  
  66. #ifdef PDCDEBUG
  67.     if (trace_on) PDC_debug("overwrit() - called\n");
  68. #endif
  69.  
  70.     if (src_w == (WINDOW *)NULL)    return( ERR );
  71.     if (dst_w == (WINDOW *)NULL)    return( ERR );
  72.  
  73.     first_col  = max(dst_w->_begx,src_w->_begx);
  74.     first_line = max(dst_w->_begy,src_w->_begy);
  75.     last_col   = min(src_w->_begx+src_w->_maxx, dst_w->_begx+dst_w->_maxx);
  76.     last_line  = min(src_w->_begy+src_w->_maxy, dst_w->_begy+dst_w->_maxy);
  77.  
  78. /* determine the overlapping region of the two windows in real coordinates */
  79.     if ((last_col < first_col) || (last_line < first_line))
  80.     return(OK);  /* if no overlapping region, do nothing */
  81.  
  82. /* size of overlapping region */
  83.     xdiff = last_col - first_col;
  84.     ydiff = last_line - first_line;
  85.  
  86.     if (src_w->_begx <= dst_w->_begx)
  87.         {
  88.         src_start_x = dst_w->_begx - src_w->_begx;
  89.         dst_start_x = 0;
  90.         }
  91.     else
  92.         {
  93.         dst_start_x = src_w->_begx - dst_w->_begx;
  94.         src_start_x = 0;
  95.         }
  96.     if (src_w->_begy <= dst_w->_begy)
  97.         {
  98.         src_start_y = dst_w->_begy - src_w->_begy;
  99.         dst_start_y = 0;
  100.         }
  101.     else
  102.         {
  103.         dst_start_y = src_w->_begy - dst_w->_begy;
  104.         src_start_y = 0;
  105.         }
  106.  
  107.     rc = PDC_copy_win(src_w,dst_w,src_start_y,src_start_x,
  108.         src_start_y+ydiff,src_start_x+xdiff,dst_start_y,dst_start_x,
  109.         dst_start_y+ydiff,dst_start_x+xdiff,FALSE);
  110.  
  111.     return( rc );
  112. }
  113.